﻿/**
 *
 * @file FITKVAOneXMLReader.h
 * @brief VA One XML读取
 * @author LiBaojun (libaojunqd@foxmail.com)
 * @date 2024-10-11
 *
 */
#ifndef _FITKVAONE_XML_READER_H___
#define _FITKVAONE_XML_READER_H___

#include "FITK_Interface/FITKInterfaceIO/FITKAbstractRapidXMLReader.h"
#include "FITK_Kernel/FITKAdaptor/FITKIOAdaptorFactory.h"

namespace rapidxml
{
    template<class Ch>
    class xml_node;
}

namespace Acoustics
{
    class FITKAcousticsDiscModel;
    class FITKAcousticsPhysics;
    class FITKAcousticsSEASubSysManager;
    class FITKSEAFaceManager;
}

namespace VAOne
{
    class FITKVAOneXMLIOInterface;
    /**
     * @brief VA One XML读取类
     * @author LiBaojun (libaojunqd@foxmail.com)
     * @date 2024-10-11
     */
    class FITKVAOneXMLReader : public Interface::FITKAbstractRapidXMLReader
    {
    public:

        /**
         * @brief   进度类型枚举
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-20
         */
        enum VAOneXMLPercentType
        {
            Per_First = 0,              ///< 开始
            Per_FrequencyDomain,        ///< 频率
            Per_Nodes,                  ///< 节点
            Per_Spectra,                ///< 频谱
            Per_Materials,              ///< 材料
            Per_FEMaterials,            ///< FE材料
            Per_PhysicalProperties,     ///< 物理属性
            Per_NoiseControlTreatments, ///< 声学包
            Per_Faces,                  ///< 面
            Per_Subsystems,             ///< 子系统
            Per_Sinks,                  ///< 半无限流体
            Per_PowerSources,           ///< 能量源
            Per_Junctions,              ///< 交点/耦合
            Per_Constraints,            ///< 约束
            Per_Connections,            ///< 连接
            Per_Finish,                 ///< 结束
            Per_FESubsystems,           ///< 结构FE子系统
            Per_AcousticFESubSystems,   ///< 腔体FE子系统
            Per_FESubSystemElementList, ///< FE子系统单元列表
        };

        /**
         * @brief   适配器读取操作模板
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-14
         */
        template <typename T>
        bool adaptorRead(QString nodeName, T* adaptor, rapidxml::xml_node<char>* node)
        {
            if (nodeName.isEmpty() || node == nullptr) return false;  // 检查node指针和节点名称是否为空

            this->consoleMessage(1, QString("Start read %1.").arg(nodeName));  // 开始读取节点数据
          
            adaptor = FITKIOADAPTORFACTORY->createT<T>("VAOneXML", nodeName);  // 获取读取适配器
            if (!adaptor) return false;
            adaptor->setNode(node);  // 设置节点

            bool ok = adaptor->adaptR();  // 适配器读取操作
            if (!ok) this->consoleMessage(3, QString("Read %1 Error.").arg(nodeName));

            delete adaptor;
            return ok;
        }

        /**
         * @brief Construct a new FITKVAOneXMLReader object
         * @param[i]  interface      组件指针，可传递参数
         * @param[o]  isSuccess      是否执行成功
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        explicit FITKVAOneXMLReader(FITKVAOneXMLIOInterface* interface, bool & isSuccess);
        /**
         * @brief Destroy the FITKVAOneXMLReader object
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        virtual ~FITKVAOneXMLReader();
        /**
         * @brief 执行读取操作
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        void run() override;

    private:
        /**
         * @brief      更新进度条
         * @param[i]   type 进度类型
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-19
         */
        void updatePercent(VAOneXMLPercentType type);

        /**
          * @brief 打印控制台消息
          * @param[i] level 打印级别 1 normal 2 warning 3error
          * @param[i] str 打印的信息
          * @author LiBaojun (libaojunqd@foxmail.com)
          * @date 2024-03-08
          */
        void consoleMessage(int level, const QString& str) override;

        /**
         * @brief clearSeaModelData 清除sea Model node face subsystem 数据
         * @author  lixiaolong (lixiaolong@diso.cn)
         * @date    2024-11-01
         */
        void clearSeaModelData();

        /**
         * @brief   清除数据
         * @author  XingXuanCi (xingxuanci@diso.cn)
         * @date    2024-11-14
         */
        void clearManagerData();

        /**
         * @brief   读取Model的SEA子节点数据部
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-14
         */
        bool readModelSEAChildNodeData(rapidxml::xml_node<char>* node);

        /**
         * @brief   读取Model的FE子节点数据部
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-14
         */
        bool readModelFEChildNodeData(rapidxml::xml_node<char>* node);

    private:
        /**
         * @brief   读取节点
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lixiaolong (lixiaolong@diso.cn)
         * @date    2024-11-01
         */
        bool readNodes(rapidxml::xml_node<char>* node);

#if 1
        /**
         * @brief   读取面数据
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readFaces(rapidxml::xml_node<char>* node);

        /**
         * @brief   读取平面数据
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readFacePlate(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager *manager);

        /**
         * @brief   读取单曲率面数据
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readFaceSingleCurve(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager *manager);

        /**
         * @brief   读取双曲率面数据
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readFaceDoubleCurve(rapidxml::xml_node<char>* node, Acoustics::FITKSEAFaceManager *manager);
#endif // 读取面数据

#if 1
        /**
         * @brief   读取SubSystem数据
         * @param[i] node 数据节点
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystem(rapidxml::xml_node<char>* node);

        /**
         * @brief   读取梁子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemBeam(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);

        /**
         * @brief   读取平板子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemPlateShell(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);

        /**
         * @brief   读取单曲率板子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemSingleCurveShell(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);

        /**
         * @brief   读取双曲率板子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemDoubleCurveShell(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);

        /**
         * @brief   读取声腔子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemCavity(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);

        /**
         * @brief   读取半无限流体子系统数据
         * @param[i] node 数据节点
         * @param[o] dataManager 子系统管理器
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2024-12-25
         */
        bool readSubSystemSemiIInfiniteFluid(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsSEASubSysManager *manager);
#endif // 读取子系统数据

        /**
         * @brief   读取材料
         * @param   materialNode
         * @return  是否执行成功
         * @author  XingXuanCi (xingxuanci@diso.cn)
         * @date    2024-11-01
         */
        bool readMaterial(rapidxml::xml_node<char>* node);
        /**
         * @brief   读取材料
         * @param   materialFENode
         * @return  是否执行成功
         * @author  XingXuanCi (xingxuanci@diso.cn)
         * @date    2024-11-15
         */
        bool readMaterialFE(rapidxml::xml_node<char>* node);
        /**
         * @brief   读取物理属性
         * @param   physicalPropNode
         * @return  是否执行成功
         * @author  liuzhiyuan(liuzhiyuan@diso.cn)
         * @date    2024-11-01
         */
        bool readPhysicalProp(rapidxml::xml_node<char>* node);
        /**
         * @brief   读取频谱
         * @param   spectraNode
         * @return  是否执行成功
         * @author  XingXuanCi (xingxuanci@diso.cn)
         * @date    2024-11-01
         */
        bool readSpectra(rapidxml::xml_node<char>* node);
        /**
         * @brief   读取频率
         * @param   frequencyDomainNode
         * @return  是否执行成功
         * @author  XingXuanCi (xingxuanci@diso.cn)
         * @date    2024-11-01
         */
        bool readrFrequencyDomain(rapidxml::xml_node<char>* node);
        /**
         * @brief   读取声包
         * @param[i] node 声包节点
         * @return  是否执行成功
         * @author  liuzhiyuan(liuzhiyuan@diso.cn)
         * @date    2024-11-01
         */
        bool readNCT(rapidxml::xml_node<char>* node);

    private:
        /**
         * @brief 组件对象指针
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        FITKVAOneXMLIOInterface* _compInterface{};
        /**
         * @brief 是否执行成功
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        bool & _isSuccess;
        /**
         * @brief 声学离散模型，读取的信息存放在这里
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        Acoustics::FITKAcousticsDiscModel* _discModel{};
        /**
         * @brief 声学物理模型，读取的信息存放在这里
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        Acoustics::FITKAcousticsPhysics* _physics{};
    };
}

#endif _FITKVAONE_XML_READER_H___
